package com.xm.controller.mobile;

import com.xm.pojo.Device;
import com.xm.service.DeviceService;
import com.xm.util.JSONMsg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by wzl on 2018/4/10.
 */
@Controller
@RequestMapping("/m/device")
public class DeviceMobileController {
    @Resource
    private DeviceService deviceService;


    /**
     * 查询全部设备信息方法
     *
     * @param device
     * @return
     */
    @RequestMapping(value = "/selectDeviceList", method = RequestMethod.GET)
    @ResponseBody
    public JSONMsg selectAll(Device device) {
        JSONMsg jsonMsg = new JSONMsg();
        List<Device> list = deviceService.selectList(device);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //配合手机端类型接收
        for(Device deviceInfo :list){
            if(deviceInfo.getUpdateTime()!=null&&!deviceInfo.getUpdateTime().equals("")){
                String dateString = formatter.format(deviceInfo.getUpdateTime());
                deviceInfo.setDeviceUpdateTime(dateString);
            }
            deviceInfo.setCreateTime(null);
            deviceInfo.setUpdateTime(null);
        }
        jsonMsg.setMsg(list);
        jsonMsg.setStatus(true);
        return jsonMsg;
    }

    /**
     * 查询设备信息详情方法
     *
     * @param device
     * @return
     */
    @RequestMapping(value = "/selectDeviceDetail", method = RequestMethod.GET)
    @ResponseBody
    public JSONMsg selectDeviceDetail(Device device) {
        JSONMsg jsonMsg = new JSONMsg();
        Device deviceInfo = deviceService.selectOne(device);
        deviceInfo.setCreateTime(null);
        deviceInfo.setUpdateTime(null);
        jsonMsg.setMsg(deviceInfo);
        jsonMsg.setStatus(true);
        return jsonMsg;
    }
}
